package com.hl.apilibrary;

import com.hl.apilibrary.bean.BaseRespose;

import retrofit2.Call;

public class ApiUtil<T> {
    public void post(Call call, final OnResultCallback<T> callback) {
        new RetrofitHelper<BaseRespose<T>>()
                .enqueue(call, new ApiCallback<BaseRespose<T>>() {

                    @Override
                    public void onSuccess(BaseRespose<T> result) {
                        if (result != null && result.status == 1) {
                            //成功
                            if (callback != null) {
                                callback.onResult(result.data);
                            }
                        } else {
                            //失败
                            if (callback != null) {
                                callback.onError(result.status, result.msg);
                            }
                        }
                    }

                    @Override
                    public void onFailure(String msg) {
                        if (callback != null) {
                            callback.onError(Integer.MAX_VALUE, "");
                        }
                    }
                });
    }
}
